//
//  ZZCReadDetailViewController.m
//  B段项目
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCReadDetailViewController.h"
#import "ZZCReadHotViewController.h"
#import "ZZCReadNewViewController.h"
@interface ZZCReadDetailViewController ()<UIScrollViewDelegate>

@property (nonatomic, retain)UIScrollView *detailListScrollV;
@property (nonatomic, retain)UIButton *btnHot;
@property (nonatomic, retain)UIButton *btnNew;

@end

@implementation ZZCReadDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.titleLabel.text = self.DetailModel.name;
    
    // 首页scrollView
    self.detailListScrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:self.detailListScrollV];
    self.detailListScrollV.delegate = self;
    self.detailListScrollV.contentSize = CGSizeMake(WIDTH * 2, 0);
    self.detailListScrollV.showsHorizontalScrollIndicator = YES;
    // 设置按页滑动
    self.detailListScrollV.pagingEnabled = YES;
    // 取消边界反弹效果
    self.detailListScrollV.bounces = NO;
    self.detailListScrollV.contentOffset = CGPointMake(0, 0);
    
    
    
    // 最新
    ZZCReadNewViewController *detailNewVC = [[ZZCReadNewViewController alloc] init];
    detailNewVC.view.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    [self.detailListScrollV addSubview:detailNewVC.view];
    [self addChildViewController:detailNewVC];
    //给子controller赋值
    detailNewVC.readNewModel = self.DetailModel;
    
    
    
    
    // 最热
    ZZCReadHotViewController *detailHotVC = [[ZZCReadHotViewController alloc] init];
    detailHotVC.view.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT);
    [self.detailListScrollV addSubview:detailHotVC.view];
    [self addChildViewController:detailHotVC];
    //给子controller赋值
    detailHotVC.hotModel = self.DetailModel;
    
    
    
    //最热按钮
    self.btnHot = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnHot.frame = CGRectMake(self.rightView.width / 8 * 7, self.rightView.height / 4, self.rightView.height / 2, self.rightView.height / 2);
    [self.btnHot setImage:[UIImage imageNamed:@"grayHot.png"] forState:UIControlStateNormal];
    [self.rightView addSubview:self.btnHot];
    [self.btnHot addTarget:self action:@selector(hotAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //最新按钮
    self.btnNew = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnNew.frame = CGRectMake(self.rightView.width / 8 * 7 - self.btnHot.width * 2, self.rightView.height / 4, self.rightView.height / 2, self.rightView.height / 2);
    [self.btnNew setImage:[UIImage imageNamed:@"blackNew.png"] forState:UIControlStateNormal];
    [self.rightView addSubview:self.btnNew];
    [self.btnNew addTarget:self action:@selector(newAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
}



//减速停止时触发
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (self.detailListScrollV.contentOffset.x == WIDTH) {
        [self.btnHot setImage:[UIImage imageNamed:@"blackHot.png"] forState:UIControlStateNormal];
        [self.btnNew setImage:[UIImage imageNamed:@"grayNew.png"] forState:UIControlStateNormal];
    }else if(self.detailListScrollV.contentOffset.x == 0){
        [self.btnNew setImage:[UIImage imageNamed:@"blackNew.png"] forState:UIControlStateNormal];
        [self.btnHot setImage:[UIImage imageNamed:@"grayHot.png"] forState:UIControlStateNormal];
    }
}

- (void)hotAction:(UIButton *)hot{
    [self.btnHot setImage:[UIImage imageNamed:@"blackHot.png"] forState:UIControlStateNormal];
    [self.btnNew setImage:[UIImage imageNamed:@"grayNew.png"] forState:UIControlStateNormal];
    self.detailListScrollV.contentOffset = CGPointMake(WIDTH, 0);
}

- (void)newAction:(UIButton *)new{
    [self.btnNew setImage:[UIImage imageNamed:@"blackNew.png"] forState:UIControlStateNormal];
    [self.btnHot setImage:[UIImage imageNamed:@"grayHot.png"] forState:UIControlStateNormal];
    self.detailListScrollV.contentOffset = CGPointMake(0, 0);
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
